package com.glueball.crm.module.client.ui;

import com.glueball.crm.module.client.model.Contact;
import com.glueball.crm.module.ui.CrmCompositeUI;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class NewContactUI extends CrmCompositeUI {
	
	@UiField TextBox  titulus;
	@UiField TextBox  firstName;
	@UiField TextBox  lastName;
	@UiField CheckBox isActive;
	
	@UiField SimplePanel phoneNumberPanel;
	
	private Contact contact;
	
	private final Widget widget;

	private static NewContactUIUiBinder uiBinder = GWT
			.create(NewContactUIUiBinder.class);

	interface NewContactUIUiBinder extends UiBinder<Widget, NewContactUI> {
	}

	public NewContactUI(Composite crmApp, Contact contact) throws Exception {
		super(crmApp);
		this.widget = uiBinder.createAndBindUi(this);
		this.contact = contact;
		//refresh();
	}

//	@Override
//	public void refresh() {
//		titulus.setText(contact.getTitulus());
//		firstName.setText(contact.getFirstName());
//		lastName.setText(contact.getLastName());
//		isActive.setValue(contact.isActive());
//		if (contact.getPhone()==null) {
//			contact.setPhone(new ArrayList<PhoneNumber>());
//		}
//		phoneNumberPanel.add(
//				new EditableListWidget<PhoneNumberWidget,PhoneNumber>(
//						contact.getPhone(),
//						this,
//						new PhoneNumberWidgetFactory()
//						).asWidget()
//				);
//	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public Contact getContact() {
		return this.contact;
	}

	@Override
	public Widget asWidget() {
	    return widget;
	}
}
